import React, { useReducer } from 'react'

const initialState = {
  count: 0
}

const reducer = (state, action) => {
  switch(action.type) {
    case 'add': 
      return {
        count: state.count + 1
      }
    case 'mimus': 
      return {
        count: state.count - 1
      }
    default: return state
  }
}

function UseReducer() {
  let [state, dispatch] = useReducer(reducer, initialState)

  return (
    <div>
      <button onClick={() => dispatch({type: 'mimus'})}>-</button>
      <span>{state.count}</span>
      <button onClick={() => dispatch({type: 'add'})}>+</button>
    </div>
  )
}


export default UseReducer
